import instance from "./axios";
import { AxiosRequestConfig } from "axios";
import {globalVariable} from '../store/modules/globalurl'

// 定义全局的基础URL
// const API_URL = 'http://101.201.173.127';
const API_URL = globalVariable;

const axios = ({
                   method,
                   url,
                   params,
                   config
               }: {
    method: string;
    url: string;
    params?: any;
    config?: AxiosRequestConfig;
}) => {
    method = method.toLowerCase();

    // 拼接完整的请求URL
    const fullUrl = `${API_URL}${url}`;

    if (method === 'post') {
        return instance.post(fullUrl, params, { ...config });
    } else if (method === 'get') {
        return instance.get(fullUrl, { params, ...config });
    } else {
        throw new Error(`Unsupported method: ${method}`);
    }
};

export default axios;
